<?php
header ( 'Content-type:application/json' );
require_once '../RSSReader/DantriReader.php';
require_once '../RSSReader/VnexpressReader.php';
require_once '../RSSReader/Bao24Reader.php';
require_once '../model/MyFrunction.php';

$data = array (
		"success" => 0,
		"data" => null 
);
$value = array ();
if (isset ( $_POST ['tag'] )) {
	$func = new MyFunction ();
	$tag = $_POST ['tag'];
	if ($tag == "startapp") {
		$news = $_POST ['news'];
		// load data
		$reader24 = new Bao24Reader ();
		$readerdt = new DantriReader ();
		$readervn = new VnexpressReader ();
		if ($news == "dantri") {
			$func->deleteAll($news);
			$readerdt->reader ();
		} elseif ($news == "vnexpress") {
			$func->deleteAll($news);
			$readervn->reader ();
		} elseif ($news == "bao24") {
			$func->deleteAll($news);
			$reader24->reader ();
		}
		// }
	} elseif ($tag == "getdata") {
		// get data
		$action = $_POST ['action'];
		$news = $_POST ['news'];
		if ($news == "dantri") {
			if ($action == "trangchu") {
				$value = $func->getDantriTT ();
			} elseif ($action == "thoisu") {
				$value = $func->getDantriTS ();
			} elseif ($action == "thegioi") {
				$value = $func->getDantriTG ();
			} elseif ($action == "thethao") {
				$value = $func->getDantriTTH ();
			} elseif ($action == "phapluat") {
				$value = $func->getDantriPL ();
			} elseif ($action == "giaitri") {
				$value = $func->getDantriGT ();
			} elseif ($action == "suckhoe") {
				$value = $func->getDantriSK ();
			}
		} elseif ($news == "vnexpress") {
			if ($action == "trangchu") {
				$value = $func->getVnexpressTT ();
			} elseif ($action == "thoisu") {
				$value = $func->getVnexpressTS ();
			} elseif ($action == "thegioi") {
				$value = $func->getVnexpressTG ();
			} elseif ($action == "thethao") {
				$value = $func->getVnexpressTTH ();
			} elseif ($action == "phapluat") {
				$value = $func->getVnexpressPL ();
			} elseif ($action == "giaitri") {
				$value = $func->getVnexpressGT ();
			} elseif ($action == "suckhoe") {
				$value = $func->getVnexpressSK ();
			}
		} elseif ($news == "bao24") {
			if ($action == "trangchu") {
				$value = $func->getBao24TT ();
			} elseif ($action == "thoisu") {
				$value = $func->getBao24TS ();
			} elseif ($action == "thegioi") {
				$value = $func->getBao24TG ();
			} elseif ($action == "thethao") {
				$value = $func->getBao24TTH ();
			} elseif ($action == "phapluat") {
				$value = $func->getBao24PL ();
			} elseif ($action == "giaitri") {
				$value = $func->getBao24GT ();
			} elseif ($action == "suckhoe") {
				$value = $func->getBao24SK ();
			}
		} else {
			$value = null;
		}
	} else {
		$value = null;
	}
} else {
	$data ["success"] = 0;
	$data ["data"] = "serrver ok";
}
if ($value != null) {
	while ( $row = mysql_fetch_array ( $value, MYSQL_ASSOC ) ) {
		@$temp [] = $row;
	}
	$data ["success"] = 1;
	$data ["data"] = @$temp;
} else {
	$data ["success"] = 0;
	$data ["data"] = null;
}

echo json_encode ( $data );